//
//  GGBaseViewController.m
//  GGProject
//
//  Created by yuemei on 2018/5/16.
//  Copyright © 2018年 yuemei. All rights reserved.
//

#import "GGBaseViewController.h"

@interface GGBaseViewController ()

@end

@implementation GGBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion{
    
    if ([viewControllerToPresent isKindOfClass:[UINavigationController class]]) {
        UIButton *backButton = [[UIButton alloc] init];
        [backButton setTitle:@"返回" forState:UIControlStateNormal];
        [backButton setTitleColor:HEXColor(0xffffff, 1) forState:UIControlStateNormal];
        backButton.titleLabel.font = [UIFont systemFontOfSize:15];
        [backButton sizeToFit];
        [backButton addTarget:self action:@selector(dismissBack) forControlEvents:UIControlEventTouchUpInside];
        
        UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
        // 调整间距
        //    UIBarButtonItem *seperator1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
        //        seperator1.width = -10;
        UINavigationController *nav = (UINavigationController *)viewControllerToPresent;
        //控制器跳转的时候隐藏tabBar
//        viewControllerToPresent.hidesBottomBarWhenPushed = YES;
        //设置导航条上的item
        nav.viewControllers.firstObject.navigationItem.leftBarButtonItems = @[leftBarButtonItem];
    }
    [super presentViewController:viewControllerToPresent animated:flag completion:completion];
    
}
-(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion{
    self.modalPresentationStyle = UIModalPresentationNone;
    [super dismissViewControllerAnimated:flag completion:completion];
}

-(void)dismissBack{
    [self dismissViewControllerAnimated:NO completion:nil];
}
@end
